package rebot

//import "time"
import "gorm.io/gorm"
import "go_part/utils"
//import "fmt"

type FunctionBasic struct{
	gorm.Model
	Name string
	LevelLocalID string
	CompanyID string
	Phone string 
	Email string 
	FunctionID string
	Descript string
 }

 func (table *FunctionBasic) TableName() string {

	return "robot_function_basic"
}

func GetFunctionBasicList() []*FunctionBasic { 
	data := make([]*FunctionBasic,10)
	utils.DB.Find(&data)
	// for _,v : = range data {
	// 	fmt.Println(v)
	// }
	return data
}

func FindFunctionBasicByName(name string) FunctionBasic {
	user := FunctionBasic{}
	utils.DB.Where("name = ?",name).Find(&user)
	return user
}

func FindFunctionBasicByTypeIDAndCompanyID(id string,CompanyID string) []*FunctionBasic {
	user := make([]*FunctionBasic,100)
	utils.DB.Where("level_local_id = ? and company_id = ?",id,CompanyID).Find(&user)
	return user
}

func FindFunctionBasicByID(id uint) FunctionBasic {
	user := FunctionBasic{}
	utils.DB.Where("id = ?",id).First(&user)
	return user
}

func CreateFunctionBasic(user FunctionBasic) *gorm.DB {
	
	return utils.DB.Create(&user)
}

func DeleteFunctionBasic(user FunctionBasic) *gorm.DB {
	
	return utils.DB.Delete(&user)
}

func UpdateFunctionBasic(user FunctionBasic) *gorm.DB {
	
	return utils.DB.Model(&user).Updates(FunctionBasic{ Descript: user.Descript})
}